/*
*   mutation模块
* */

import Vue from 'vue'
import {RECEIVE_ADDRESS,RECEIVE_CATEGORY,RECEIVE_SHOPS,RECEIVE_USERLOGIN,RECEIVE_LOGOUT,RECEIVE_INFO,RECEIVE_GOODS,RECEIVE_RATINGS,RECTIVE_SHOPSIMG,INCREMENT_FOOD_COUNT,DECREMENT_FOOD_COUNT} from './mutation-type'

export default {
  //接收定位信息，并且存储state里address属性
  [RECEIVE_ADDRESS](state,{address}){
    state.address = address;
  },
  //接收商品分类信息，并且存储state里category属性
  [RECEIVE_CATEGORY](state,{category}){
    state.category = category;
  },
  //接收商家信息，并且存储state里shops属性
  [RECEIVE_SHOPS](state,{shops}){
    state.shops = shops;
  },
  //接收用户登陆信息，并且存储state里userLogin属性
  [RECEIVE_USERLOGIN](state,{userLogin}){
    state.userLogin = userLogin;
  },
  //接收用户退出登陆信息，并且存储state里userLogin属性
  [RECEIVE_LOGOUT](state){
    state.userLogin = {};
  },
  //接收商家头部信息，并且存储state里infon属性
  [RECEIVE_INFO](state,{info}){
    state.info = info;
  },
  //接收商品信息，并且存储state里goods属性
  [RECEIVE_GOODS](state,{goods}){
    state.goods = goods;
  },
  //接收评价信息，并且存储state里ratings属性
  [RECEIVE_RATINGS](state,{ratings}){
    state.ratings = ratings;
  },
  //接收商家图片信息，更新state
  [RECTIVE_SHOPSIMG](state,{shopsImg}){
    state.shopsImg = shopsImg
  },
  //
  [INCREMENT_FOOD_COUNT](state,{foods}){
    if(!foods.count){
      Vue.set(foods , 'count' ,1)
    }else{
      foods.count++
    }
  },
  //
  [DECREMENT_FOOD_COUNT](state,{foods}){
    if(foods.count){
      foods.count--
    }
  }
}
